###################################################################################################
## Payson (2018) "Cities in the Statehouse" Replication Code
## On-Line Appendix
## Created with R version 3.4.1 (2017-06-30) -- "Single Candle"
###################################################################################################

## Set working directory
setwd()

## Load packages 
library(ggplot2); library(plyr); library(plm); library(lmtest); library(effects); 
library(stargazer); library(sandwich); library(RColorBrewer); library(reshape);
library(statar); library(xtable); library(scales)


## Functions for tables (Note: tables will not compile without these functions)
pretty <- function(x) {
  paste(prettyNum(x, big.mark = ","))
}

clusters <- function(x) {
  length(fixef(x))
}

N <- function(x) {
  dim(x$model)[1]
}



###########################################################################################
## Figure A1: Lobbying Expenditures in California, 1999 - 2015
###########################################################################################

dta <- read.csv("ca_lobbying_timeseries.csv")

dta$Sector <- factor(dta$Sector, 
                     levels = c("Local Government", "Health Care", "Manufacturing", 
                                "Finance", "Oil and Gas", "Education", "Labor Unions", 
                                "Professional/ Trade", "Utilities", "Transportation", 
                                "Entertainment", "Real Estate", "Retail", "Agriculture", 
                                "Legal", "Public Employees", "Lodging/ Restaurants", 
                                "Political Organizations", "Miscellaneous"))

dta <- na.omit(subset(dta, Sector == "Local Government" | Sector == "Health Care" | 
                        Sector == "Manufacturing" | Sector == "Finance" | 
                        Sector == "Oil and Gas" | Sector == "Education" | 
                        Sector == "Labor Unions" | Sector == "Professional/ Trade"))


## Figure A1: Lobbying Expenditures in California, 1999-2015
ggplot(dta, aes(x=year, y=dollars_2013, group=Sector)) +
  geom_line(aes(colour=Sector), size = 1) + 
  xlab("Legislative Session") + 
  ylab("2015 Dollars") +
  coord_cartesian(xlim=c(1999,2015)) +
  scale_x_continuous(breaks=seq(1999, 2015, 3)) +
  scale_y_continuous(labels=comma) +
  scale_colour_discrete(name = "Interest Sector") +
  theme_bw(base_size = 13, base_family = "serif") +
  theme(plot.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        strip.background = element_rect(fill = "white"))



###################################################################################################
## Table A1: Descriptive Statistics for Lobbying and Non-Lobbying Cities, 2007 and 2012
###################################################################################################

## Read in 50-state data
load("50statelobby.RData")

tab <- rbind.data.frame(tapply(dta$state.rev.pp, dta$state.lobby.lag1, function(x) mean(x, na.rm = T)),
                        tapply(dta$pop, dta$state.lobby.lag1, function(x) mean(x, na.rm = T)),
                        tapply(dta$median.income, dta$state.lobby.lag1, function(x) mean(x, na.rm = T)),
                        tapply(dta$property.tax.pp, dta$state.lobby.lag1, function(x) mean(x, na.rm = T)),
                        tapply(dta$rev.own.source.pp, dta$state.lobby.lag1, function(x) mean(x, na.rm = T)),
                        tapply(dta$pct.white, dta$state.lobby.lag1, function(x) mean(x, na.rm = T)))

names(tab) = c("Non-Lobbying Cities", "Lobbying Cities")
row.names(tab) = c("State Transfers Per Person", "Population", "Median Income", "Property Tax Per Person", 
                   "Own Source Revenue Per Person", "Percent White")

## Table A1 in Appendix          
tab$t <- c(t.test(dta$state.rev.pp ~ dta$state.lobby.lag1)[1],
            t.test(dta$pop ~ dta$state.lobby.lag1)[1],
            t.test(dta$median.income ~ dta$state.lobby.lag1)[1],
            t.test(dta$property.tax.pp ~ dta$state.lobby.lag1)[1],
            t.test(dta$rev.own.source.pp ~ dta$state.lobby.lag1)[1],
            t.test(dta$pct.white ~ dta$state.lobby.lag1)[1])

print(tab)



###################################################################################################
## Table A2: Descriptive Statistics on California City Lobbying, 2002 - 2015
###################################################################################################

load("ca_lobby2002-2015.RData")

## Subset to variables to summarize
summary <- data.frame(state.rev.pp = dta$state.pp, 
                      lobby.indicator = dta$lobby,
                      pop = dta$pop,
                      log.taxes = dta$log.taxes,
                      log.liabilities = dta$log.liabilities,
                      log.trans = dta$log.trans,
                      log.utilites = dta$log.utilities,
                      log.pubsafety = dta$log.pubsafety,
                      log.health = dta$log.health,
                      log.commdev = dta$log.commdev,
                      log.parks = dta$log.parks,
                      log.mean.inc = dta$log.mean.inc,
                      white.pct = dta$white.pct,
                      poverty = dta$poverty,
                      republican = dta$republican)

## Table 2: Descriptive Statistics on California City Lobbying, 2002 - 2015
stargazer(summary, type = "text", 
          table.placement = "!htb", label = "table:summary",  
          summary.stat = c("mean", "sd", "min", "max"), 
          digits = 2, digits.extra = 0,
          digit.separator = ",", font.size = "footnotesize",
          title = paste("\\textbf{Descriptive Statistics on California City Lobbying, 2002 - 2015.}", 
                        "Statistics pooled across years."))



###################################################################################################
## Figure A3: California City Lobbying by Year
###################################################################################################

dta <- read.csv("ca_city_2000-2016LobbyFull.csv")

## Note that these data include all instances of city lobbying in each year. The full data set with
## city financial and demographic variables (ca_lobby2002-2015.RData) are missing a few observations 
## (less than 1%)

## Percent of cities lobbying per year
lobby.by.year <- ddply(dta, .(year), summarize,
                       nlobby = sum(lobby),
                       lobby = mean(lobby))

nlobby <- c("n=106", lobby.by.year$nlobby[2:17])

## Figure A3: California City Lobbying by Year
ggplot(lobby.by.year, aes(x = year, y = lobby)) +
  geom_bar(stat = "identity", alpha = .8) + 
  scale_x_continuous(breaks=seq(2000, 2016)) +
  ylim(0, .45) +
  annotate("text", x=seq(2000, 2016), y = lobby.by.year$lobby + .01, label = nlobby, 
           family = "serif", size = 4.5) +
  labs(y = "Proportion Cities Lobbying", x = "Year") +
  theme_bw(base_family = "serif", base_size = 15) +
  theme(axis.title = element_text(size = 19))



###################################################################################################
## Table A3: City Lobbying and State Revenue Transfers: Time Trend Specifications
###################################################################################################

load("ca_lobby2002-2015.RData")

## Note: these models are slow to run
m <- plm(state.pp1 ~ lobby + log.pop + log.taxes + year + city, data = dta)
coef <- coeftest(m, vcov = vcovHC(m, method = "arellano", type = "HC1", cluster = "group"))

m1 <- lm(state.pp1 ~ lobby + log.pop + log.taxes + year + city*trend, data = dta)
coef1 <- coeftest(m1, vcov = vcovHC(m1, method = "arellano", type = "HC1", cluster = "group"))

m2 <- lm(state.pp1 ~ lobby + log.pop + log.taxes + year + city*I(trend^2), data = dta)
coef2 <- coeftest(m2, vcov = vcovHC(m2, method = "arellano", type = "HC1", cluster = "group"))

m3 <- lm(state.pp1 ~ lobby + log.pop + log.taxes + year + city*I(trend^3), data = dta)
coef3 <- coeftest(m3, vcov = vcovHC(m3, method = "arellano", type = "HC1", cluster = "group"))


## Table A3: City Lobbying and State Revenue Transfers: Time Trend Specifications
stargazer(coef, coef1, coef2, coef3, type = "text", star.cutoffs = c(0.05),
          title = "City Lobbying and State Revenue Transfers: Time Trend Specifications", 
          dep.var.caption = c("City Revenue Per Capita From State, t + 1"), 
          keep = c("lobby", "log.pop", "log.taxes"),
          order = 	c("lobby", "log.pop", "log.taxes"),
          covariate.labels = c("Lobby, t", "Population (Log)", "Tax Revenue (Log)"),
          add.lines = list(c("City FE", "Y", "Y", "Y", "Y"), 
                           c("City FE x Time Trend", "", "Y", "", ""),
                           c("City FE x Quadratic Time Trend", "", "", "Y", ""),
                           c("City FE x Cubic Time Trend", "", "", "", "Y"),
                           c("Year FE", "Y", "Y", "Y", "Y"),
                           c("Observations", pretty(dim(m$model)[1]), pretty(dim(m1$model)[1]),
                             pretty(dim(m2$model)[1]), pretty(dim(m3$model)[1])),
                           c("\\# Cities", pretty(length(levels(m1$model$city))), 
                             pretty(length(levels(m1$model$city))),
                             pretty(length(levels(m2$model$city))), 
                             pretty(length(levels(m3$model$city))))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")		

          

###################################################################################
## Table A4: City Lobbying and State Revenue Transfers: Lags and Leads
###################################################################################

## Note: continue to use ca_lobby2002-2015.RData for rest of Appendix analyses
load("ca_lobby2002-2015.RData")

## Format for use with "plm" package
pdta <- pdata.frame(dta, index=c("city", "year"))


m1 <- plm(state.pp1 ~ lobby + log.pop + log.taxes + year, 
                   data = pdta, model = "within")
coef1 <- coeftest(m1, vcov = vcovHC(m1, method = "arellano", 
                                             type = "HC1", cluster = "group"))

m2 <- plm(state.pp1 ~ lobby.lag1 + lobby + log.pop + log.taxes + year,
                   data = pdta, model = "within")
coef2 <- coeftest(m2, vcov = vcovHC(m2, method = "arellano", 
                                             type = "HC1", cluster = "group"))

m3 <- plm(state.pp1 ~ lobby.lag1 + lobby + lobby.lead1 + log.pop + 
                     log.taxes + year, data = pdta, model = "within")
coef3 <- coeftest(m3, vcov = vcovHC(m3, method = "arellano", 
                                             type = "HC1", cluster = "group"))

m4 <- plm(state.pp1 ~ lobby.lag1 + lobby + lobby.lead1 + lobby.lead2 +
                     log.pop + log.taxes + year, data = pdta, model = "within")
coef4 <- coeftest(m4, vcov = vcovHC(m4, method = "arellano", 
                                             type = "HC1", cluster = "group"))

m5 <- plm(state.pp1 ~ lobby.lag1 + lobby + lobby.lead1 + lobby.lead2 +
                     lobby.lead3 + log.pop + log.taxes + year, data = pdta, 
                   model = "within")
coef5 <- coeftest(m5, vcov = vcovHC(m5, method = "arellano", 
                                             type = "HC1", cluster = "group"))


## Table A4: City Lobbying and State Revenue Transfers: Lags and Leads
stargazer(coef1, coef2, coef3, coef4, coef5, star.cutoffs = c(0.05), type = "text",
          title = "City Lobbying and State Revenue Transfers: Lags and Leads.",
          dep.var.caption = "City Revenue Per Capita From State, t + 1",
          keep = c("lobby.lag1", "lobby", "lobby.lead1", "lobby.lead2", "log.pop", "log.taxes"),
          covariate.labels = c("Lobby, t+2", "Lobby, t+1", "Lobby, t",
                               "Lobby, t-1", "Population (Log), t",
                               "Tax Revenue (Log), t"),
          add.lines = list(c("City FE", "Y", "Y", "Y", "Y", "Y"), 
                           c("Year FE", "Y", "Y", "Y", "Y", "Y"),
                           c("Observations", pretty(N(m1)), pretty(N(m2)),
                             pretty(N(m3)), pretty(N(m4)), pretty(N(m5))),
                           c("# Cities", pretty(clusters(m1)), pretty(clusters(m2)),
                             pretty(clusters(m3)), pretty(clusters(m4)), pretty(clusters(m5)))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")



###################################################################################################
## Table A5: City Lobbying and Log State Revenue Transfers in California
###################################################################################################

load("ca_lobby2002-2015.RData")

## Format for use with "plm" package
pdta <- pdata.frame(dta, index=c("city", "year"))


m1 <- plm(log.state1 ~ lobby + year, data = pdta, model = "within")
coef1 <- coeftest(m1, vcov = vcovHC(m1, method = "arellano", type = "HC1", cluster = "group"))

m2 <- plm(log.state1 ~ lobby + log.pop + year, data = pdta, model = "within")
coef2 <- coeftest(m2, vcov = vcovHC(m2, method = "arellano", type = "HC1", cluster = "group"))

m3 <- plm(log.state1 ~ lobby + log.pop + log.taxes + year, 
          data = pdta, model = "within")
coef3 <- coeftest(m3, vcov = vcovHC(m3, method = "arellano", type = "HC1", cluster = "group"))

m4 <- plm(log.state1 ~ lobby + log.pop + log.taxes + log.liabilities + republican +
            year, data = pdta, model = "within")
coef4 <- coeftest(m4, vcov = vcovHC(m4, method = "arellano", type = "HC1", cluster = "group"))


## Table A5: City Lobbying and Log State Revenue Transfers in California
stargazer(coef1, coef2, coef3, coef4, type = "text", star.cutoffs = c(0.05),
          title = "City Lobbying and Log State Revenue Transfers in California.",
          dep.var.caption = "State Transfers (Log), t + 1",
          keep = c("lobby", "log.pop", "log.taxes", "log.liabilities", "republican"),
          covariate.labels = c("Lobby, t", "Population (Log), t",
                               "Tax Revenue (Log), t", "Total Liabilities (Log), t", 
                               "Republican Assembly Rep., t"),
          add.lines = list(c("City FE", "Y", "Y", "Y", "Y"), 
                           c("Year FE", "Y", "Y", "Y", "Y"),
                           c("Observations", pretty(N(m1)), pretty(N(m2)),
                             pretty(N(m3)), pretty(N(m4))),
                           c("# Cities", pretty(clusters(m1)), pretty(clusters(m2)),
                             pretty(clusters(m3)), pretty(clusters(m4)))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")	



###################################################################################
## Table A6: City Lobbying and State Transfers by Local Revenue Tercile
###################################################################################

load("ca_lobby2002-2015.RData")

## Format for use with "plm" package
pdta <- pdata.frame(dta, index=c("city", "year"))

m1 <- plm(state.pp1 ~ lobby*rev.tercile + log.pop + year, data = pdta, model = "within")
coef1 <- coeftest(m1, vcov = vcovHC(m1, method = "arellano", 
                                           type = "HC1", cluster = "group"))

m2 <- plm(state.pp1 ~ lobby*rev.tercile + log.pop + log.taxes + year, 
                data = pdta, model = "within")
coef2 <- coeftest(m2, vcov = vcovHC(m2, method = "arellano", 
                                           type = "HC1", cluster = "group"))

m3 <- plm(state.pp1 ~ lobby*rev.tercile + log.pop + log.taxes + log.liabilities + 
                  republican + year, data = pdta, model = "within")
coef3 <- coeftest(m3, vcov = vcovHC(m3, method = "arellano", 
                                           type = "HC1", cluster = "group"))

## Table A6: City Lobbying and State Transfers by Local Revenue Tercile
stargazer(coef1, coef2, coef3, type = "text", star.cutoffs = c(0.05),
          title = "City Lobbying and State Transfers by Local Revenue Tercile.", 
          dep.var.caption = c("State Transfers Per Capita, t + 1"),
          keep = c("lobby", "lobby:revtercilemiddle", "lobby:revterciletop", 
                   "log.pop", "log.taxes", "log.liabilities", "republican", "rev.tercile"),
          order = 	c("lobby", "lobby:revtercilemiddle", "lobby:revterciletop", 
                     "rev.tercile", "log.pop", "log.taxes", "log.liabilities", "republican"),
          covariate.labels = c("Lobby (Bottom Tercile), t", "Lobby x Middle Rev Tercile, t", 
                               "Lobby x Top Rev Tercile, t", "Middle Revenue Tercile, t",
                               "Top Revenue Tercile, t", "Population (Log), t",
                               "Tax Revenue (Log), t", "Total Liabilities  (Log), t", 
                               "Republican Assembly Rep., t"),
          add.lines = list(c("City FE", "Y", "Y", "Y"), 
                           c("Year FE", "Y", "Y", "Y"),
                           c("Observations", pretty(N(m1)), pretty(N(m2)), pretty(N(m3))),
                           c("\\# Cities", pretty(clusters(m1)), pretty(clusters(m2)),
                             pretty(clusters(m3)))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")		



###################################################################################
## Table A7: City Lobbying and State Transfers by City Revenue Tercile (Log Scale)
###################################################################################

load("ca_lobby2002-2015.RData")

## Format for use with "plm" package
pdta <- pdata.frame(dta, index=c("city", "year"))

m1 <- plm(log.state1 ~ lobby*rev.tercile + log.pop + year, data = pdta, model = "within")
coef1 <- coeftest(m1, vcov = vcovHC(m1, method = "arellano", 
                                     type = "HC1", cluster = "group"))

m2 <- plm(log.state1 ~ lobby*rev.tercile + log.pop + log.taxes + year, 
          data = pdta, model = "within")
coef2 <- coeftest(m2, vcov = vcovHC(m2, method = "arellano", 
                                     type = "HC1", cluster = "group"))

m3 <- plm(log.state1 ~ lobby*rev.tercile + log.pop + log.taxes + log.liabilities + 
            republican + year, data = pdta, model = "within")
coef3 <- coeftest(m3, vcov = vcovHC(m3, method = "arellano", 
                                     type = "HC1", cluster = "group"))

## Table A7: City Lobbying and State Transfers by City Revenue Tercile (Log Scale)
stargazer(coef1, coef2, coef3, type = "text", star.cutoffs = c(0.05),
          title = "City Lobbying and State Transfers by City Revenue Tercile (Log Scale)", 
          dep.var.caption = c("State Transfers (Log), t + 1"),
          keep = c("lobby", "lobby:revtercilemiddle", "lobby:revterciletop", 
                   "log.pop", "log.taxes", "log.liabilities", "republican", "rev.tercile"),
          order = 	c("lobby", "lobby:revtercilemiddle", "lobby:revterciletop", 
                     "rev.tercile", "log.pop", "log.taxes", "log.liabilities", "republican"),
          covariate.labels = c("Lobby (Bottom Tercile), t", "Lobby x Middle Rev Tercile, t", 
                               "Lobby x Top Rev Tercile, t", "Middle Revenue Tercile, t",
                               "Top Revenue Tercile, t", "Population (Log), t",
                               "Tax Revenue (Log), t", "Total Liabilities  (Log), t", 
                               "Republican Assembly Rep., t"),
          add.lines = list(c("City FE", "Y", "Y", "Y"), 
                           c("Year FE", "Y", "Y", "Y"),
                           c("Observations", pretty(N(m1)), pretty(N(m2)), pretty(N(m3))),
                           c("\\# Cities", pretty(clusters(m1)), pretty(clusters(m2)),
                             pretty(clusters(m3)))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")		



###################################################################################
## Table A8: City Lobbying and State Transfers by City Revenue Tercile (Fixed)
###################################################################################

load("ca_lobby2002-2015.RData")

## Format for use with "plm" package
pdta <- pdata.frame(dta, index=c("city", "year"))

m1 <- plm(state.pp1 ~ lobby*rev.tercile.fixed + log.pop + year, data = pdta, model = "within")
coef1 <- coeftest(m1, vcov = vcovHC(m1, method = "arellano", 
                                    type = "HC1", cluster = "group"))

m2 <- plm(state.pp1 ~ lobby*rev.tercile.fixed + log.pop + log.taxes + year, 
          data = pdta, model = "within")
coef2 <- coeftest(m2, vcov = vcovHC(m2, method = "arellano", 
                                    type = "HC1", cluster = "group"))

m3 <- plm(state.pp1 ~ lobby*rev.tercile.fixed + log.pop + log.taxes + log.liabilities + 
            republican + year, data = pdta, model = "within")
coef3 <- coeftest(m3, vcov = vcovHC(m3, method = "arellano", 
                                    type = "HC1", cluster = "group"))

## Table A8: City Lobbying and State Transfers by City Revenue Tercile (Fixed)
stargazer(coef1, coef2, coef3, type = "text", star.cutoffs = c(0.05),
          title = "City Lobbying and State Transfers by City Revenue Tercile (Fixed)", 
          dep.var.caption = c("State Transfers Per Capita, t + 1"),
          keep = c("lobby", "lobby:revtercilemiddle", "lobby:revterciletop", 
                   "log.pop", "log.taxes", "log.liabilities", "republican", "rev.tercile"),
          order = 	c("lobby", "lobby:revtercilemiddle", "lobby:revterciletop", 
                     "rev.tercile", "log.pop", "log.taxes", "log.liabilities", "republican"),
          covariate.labels = c("Lobby (Bottom Tercile), t", 
                               "Lobby x Middle Rev Tercile, t", 
                               "Lobby x Top Rev Tercile, t", "Population (Log), t",
                               "Tax Revenue (Log), t", "Total Liabilities  (Log), t", 
                               "Republican Assembly Rep., t"),
          add.lines = list(c("City FE", "Y", "Y", "Y"), 
                           c("Year FE", "Y", "Y", "Y"),
                           c("Observations", pretty(N(m1)), pretty(N(m2)), pretty(N(m3))),
                           c("\\# Cities", pretty(clusters(m1)), pretty(clusters(m2)),
                             pretty(clusters(m3)))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")		



###################################################################################
## Table A9: City Lobbying Effort and State Transfers
###################################################################################

load("ca_lobby2002-2015.RData")

## Format for use with "plm" package
pdta <- pdata.frame(dta, index=c("city", "year"))


## Specify interactions for easier use with stargazer
pdta$top.some.lobby <- ifelse(pdta$lobby.effort == "Any Lobby" & 
                                pdta$rev.tercile == "top", 1, 0)
pdta$top.lobby100k <- ifelse(pdta$lobby.effort == "Over 100K" & 
                               pdta$rev.tercile == "top", 1, 0)

pdta$mid.some.lobby <- ifelse(pdta$lobby.effort == "Any Lobby" & 
                                pdta$rev.tercile == "middle", 1, 0)
pdta$mid.lobby100k <- ifelse(pdta$lobby.effort == "Over 100K" & 
                               pdta$rev.tercile == "middle", 1, 0)

pdta$bottom.some.lobby <- ifelse(pdta$lobby.effort == "Any Lobby" & 
                                   pdta$rev.tercile == "bottom" , 1, 0)
pdta$bottom.lobby100k <- ifelse(pdta$lobby.effort == "Over 100K" & 
                                  pdta$rev.tercile == "bottom", 1, 0)

m <- plm(state.pp1 ~ bottom.some.lobby + bottom.lobby100k + mid.some.lobby + 
                mid.lobby100k + top.some.lobby + top.lobby100k + rev.tercile + 
                log.pop + log.taxes + year, data = pdta, model = "within")
(coef <- coeftest(m, vcov = vcovHC(m, method = "arellano", type = "HC1", cluster = "group")))


## Table A9: City Lobbying Effort and State Transfers
stargazer(coef, type = "text", star.cutoffs = c(0.05),
          title = "City Lobbying Effort and State Transfers.",
          dep.var.caption = c("State Transfers Per Capita, t + 1"), keep = c(1:10),
          covariate.labels = c("Any Lobby (Bottom Tercile), t", "100K Lobby (Bottom Tercile), t",
                               "Any Lobby x Middle Rev. Tercile, t", 
                               "100K Lobby x Middle Rev. Tercile, t",
                               "Any Lobby x Top Rev. Tercile, t", 
                               "100K Lobby x Top Rev. Tercile, t",
                               "Middle Revenue Tercile, t", "Top Revenue Tercile, t", 
                               "Population (Log), t"),
          add.lines = list(c("City FE", "Y"), c("Year FE", "Y"),
                           c("Observations", pretty(N(m))), c("\\# Cities", pretty(clusters(m)))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")	



###################################################################################
## Table A10: City Lobbying Per Capita and State Transfers
###################################################################################

load("ca_lobby2002-2015.RData")

## Format for use with "plm" package
pdta <- pdata.frame(dta, index=c("city", "year"))

m <- plm(state.pp1 ~ lobby.pp + year, data = pdta, model = "within")
coef <- coeftest(m, vcov = vcovHC(m, method = "arellano", 
                                    type = "HC1", cluster = "group"))

m1 <- plm(state.pp1 ~ lobby.pp + log.pop + year, data = pdta, model = "within")
coef1 <- coeftest(m1, vcov = vcovHC(m1, method = "arellano", 
                                    type = "HC1", cluster = "group"))

m2 <- plm(state.pp1 ~ lobby.pp + log.pop + log.taxes + year, 
          data = pdta, model = "within")
coef2 <- coeftest(m2, vcov = vcovHC(m2, method = "arellano", 
                                    type = "HC1", cluster = "group"))

m3 <- plm(state.pp1 ~ lobby.pp + log.pop + log.taxes + log.liabilities + 
            republican + year, data = pdta, model = "within")
coef3 <- coeftest(m3, vcov = vcovHC(m3, method = "arellano", 
                                    type = "HC1", cluster = "group"))

## Table A10: City Lobbying Per Capita and State Transfers
stargazer(coef, coef1, coef2, coef3, type = "text", star.cutoffs = c(0.05),
          title = "City Lobbying Per Capita and State Transfers", 
          dep.var.caption = c("State Transfers Per Capita, t + 1"),
          keep = c("lobby.pp", "log.pop", "log.taxes", "log.liabilities", "republican"),
          covariate.labels = c("Lobby, t", "Population (Log), t",
                               "Tax Revenue (Log), t", "Total Liabilities (Log), t", 
                               "Republican Assembly Rep., t"),
          add.lines = list(c("City FE", "Y", "Y", "Y", "Y"), 
                           c("Year FE", "Y", "Y", "Y", "Y"),
                           c("Observations", pretty(N(m1)), pretty(N(m2)),
                             pretty(N(m3)), pretty(N(m4))),
                           c("# Cities", pretty(clusters(m1)), pretty(clusters(m2)),
                             pretty(clusters(m3)), pretty(clusters(m4)))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")	



###################################################################################
## Table A11: City Lobbying Per Capita and State Transfers by City Revenue Tercile
###################################################################################

load("ca_lobby2002-2015.RData")

## Format for use with "plm" package
pdta <- pdata.frame(dta, index=c("city", "year"))


m1 <- plm(state.pp1 ~ lobby.pp*rev.tercile + log.pop + year, data = pdta, model = "within")
coef1 <- coeftest(m1, vcov = vcovHC(m1, method = "arellano", 
                                    type = "HC1", cluster = "group"))

m2 <- plm(state.pp1 ~ lobby.pp*rev.tercile + log.pop + log.taxes + year, 
          data = pdta, model = "within")
coef2 <- coeftest(m2, vcov = vcovHC(m2, method = "arellano", 
                                    type = "HC1", cluster = "group"))

m3 <- plm(state.pp1 ~ lobby.pp*rev.tercile + log.pop + log.taxes + log.liabilities + 
            republican + year, data = pdta, model = "within")
coef3 <- coeftest(m3, vcov = vcovHC(m3, method = "arellano", 
                                    type = "HC1", cluster = "group"))

## Table A11: City Lobbying Per Capita and State Transfers by City Revenue Tercile
stargazer(coef1, coef2, coef3, type = "text", star.cutoffs = c(0.05),
          title = "City Lobbying Per Capita and State Transfers by City Revenue Tercile", 
          dep.var.caption = c("State Transfers Per Capita, t + 1"),
          keep = c("lobby.pp", "lobby.pp:revtercilemiddle", "lobby.pp:revterciletop", 
                   "log.pop", "log.taxes", "log.liabilities", "republican", "rev.tercile"),
          order = 	c("lobby.pp", "lobby.pp:revtercilemiddle", "lobby.pp:revterciletop", 
                     "rev.tercile", "log.pop", "log.taxes", "log.liabilities", "republican"),
          covariate.labels = c("Lobby Amount Per Capita (Bottom Tercile), t", 
                               "Lobby Per Capita x Middle Rev Tercile, t", 
                               "Lobby Per Capita x Top Rev Tercile, t", "Middle Revenue Tercile, t",
                               "Top Revenue Tercile, t", "Population (Log), t",
                               "Tax Revenue (Log), t", "Total Liabilities  (Log), t", 
                               "Republican Assembly Rep., t"),
          add.lines = list(c("City FE", "Y", "Y", "Y"), 
                           c("Year FE", "Y", "Y", "Y"),
                           c("Observations", pretty(N(m1)), pretty(N(m2)), pretty(N(m3))),
                           c("\\# Cities", pretty(clusters(m1)), pretty(clusters(m2)),
                             pretty(clusters(m3)))),
          notes = paste("Robust standard errors clustered by city. *p<0.05"),
          notes.append = FALSE, notes.align = "l", notes.label  = "")		

